package com.piao.springboot_task;

import com.piao.springboot_task.service.AsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 测试异步任务
 */

@RestController
public class TestController {

    //注入业务对象
    @Resource
    AsyncService asyncService;

    //测试同步
    @GetMapping("/testSync")
    public String testSync(){
        asyncService.testSync();
        return "Sync success！同步执行";//耗时操作阻塞线程，10秒后返回结果
    }

    //测试异步
    @GetMapping("/testAsync")
    public String testAsync(){
        asyncService.testAsync();
        return "Async success！异步执行";//耗时操作异步执行，没有阻塞线程，立即返回结果
    }

}
